package offer;

import java.util.Arrays;

public class  Offer45 {
        /**
         * 新的排序规则解题
         * @param numbers
         * @return
         */
        public String printMinNumber(int [] numbers) {
            // 防止特殊输入
            if (numbers == null || numbers.length == 0) {
                return "";
            }
            // 以防两个数相加溢出，将int 变成 string
            String[] numberStrings = new String[numbers.length];
            for (int i = 0; i < numbers.length; i++) {
                numberStrings[i] = numbers[i] + "";
            }

            // 利用新的排序规则排序
            Arrays.sort(numberStrings, (s1, s2) -> (s1 + s2).compareTo(s2 + s1));
            StringBuilder result = new StringBuilder();



            for (String s : numberStrings) {
                System.out.println(s);
                result.append(s);
            }


            return result.toString();
        }

    public static void main(String[] args) {
        Offer45 offer45 = new Offer45();
         int[] nums={3,30,34,5,9};
        String s = offer45.printMinNumber(nums);
        System.out.println(s);



//        String str1="303";
//        String str2="330";
//        System.out.println(str1.compareTo(str2));



//        Integer[] arr = {5,4,7,9,2,12,54,21,1};
//        //降序
//        Arrays.sort(arr, (a, b) -> {
//            //返回值>0交换
//            return b-a;
//        });
//        System.out.println(Arrays.toString(arr));


    }




    }


